/*******************************************************************************
 * Copyright 2009 DCSpectrometer - http://code.google.com/p/dcspectrometer 
 *  
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 *  
 *     http://www.apache.org/licenses/LICENSE-2.0 
 *     
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 *******************************************************************************/
package com.dcspectrometer.Analysis;

/** This class calculates the standard deviation of a sequence of numbers. */
public class StandardDeviation implements IStatCalculator{

	Variance _s2 = new Variance();
	double _s;
	long _n = 0;
	
	public StandardDeviation(){
		_n = 0;
		_s = Double.NaN;
	}

	public void addValue(double value) {
			_n++;
			_s2.addValue(value);
			_s = Math.sqrt(_s2.getResults());
	}

	public String getName() {
		return "StandardDeviation";
	}

	public IStatCalculator getNew() {
		return new StandardDeviation();
	}

	public double getResults() {
		return _s;
	}
	
}
